﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DBUtils;


/// <summary>
/// 该页面对应着功能说明书的历史记录查询页。
/// </summary>
public partial class SubmitOverTime_History : System.Web.UI.Page
{
    DataSet ds;
    /// <summary>
    /// 网页初始化时执行该方法。设置控件属性
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            txtStartTime.Text = "2000-01-01";
            txtEndTime.Text = "2010-01-01";
            RadioButtonList1.SelectedIndex = 1;
        }
    }

    /// <summary>
    /// 当用户单击“搜索”按钮时，该方法将员工的历史加班记录以 DataGrid 的形式显示。
    /// 该过程调用 
    /// SubmitOTReq.QueryHistoryReq(CInt(Session("EmployeeID")), iType, txtStartTime.Text.Trim, txtEndTime.Text.Trim, dsResult) 函数，
    /// 在数据库中检索该员工该段时间内的加班记录。
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button1_Click(object sender, EventArgs e)
    {
        ds = new DataSet();
        try
        {
            int ok = SubmitOTReq.QueryHistoryReq(Convert.ToInt32(Session["EmployeeID"]), Convert.ToInt32(RadioButtonList1.SelectedValue), txtStartTime.Text.Trim(), txtEndTime.Text.Trim(), ref ds);

            if (ds.Tables[0].Rows.Count == 0)
            {
                lblMessage.Text = "没有查到相应的记录";
                lblMessage.Visible = true;
                grdResult.Visible = false;
                return;
            }
            grdResult.DataSource = ds.Tables[0];
            grdResult.DataBind();
            grdResult.Visible = true;
            lblMessage.Visible = false;
        }

        catch (Exception msg)
        {
            this.Response.Write("<script>alert('" + "查询失败！请检查输入格式" + "');</script>");
        }

    }

    /// <summary>
    /// 当用户单击 DataGrid 中的“详细情况”链接时，该方法将在DataGrid 上方显示该条加班记录的详细信息。
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {

    }


    protected void grdResult_SelectedIndexChanged(object sender, EventArgs e)
    {
        Panel1.Visible = true;

        int i = grdResult.SelectedIndex;
        DataSet ds1 = new DataSet();
        int ok = SubmitOTReq.QueryHistoryReq(Convert.ToInt32(Session["EmployeeID"]), Convert.ToInt32(RadioButtonList1.SelectedValue), txtStartTime.Text.Trim(), txtEndTime.Text.Trim(), ref ds1);
        this.lblApproverName.Text = ds1.Tables[0].Rows[i][11].ToString();
        this.lblReason.Text = ds1.Tables[0].Rows[i][6].ToString();
        this.lblDenyReason.Text = ds1.Tables[0].Rows[i][10].ToString();

    }
}
